// src/models/Role.ts
import { DataTypes, Model, Optional } from 'sequelize';
import sequelize from '../config/db';

interface RoleAttributes {
  role_id: number;
  role_name: string;
  role_desc?: string;
}

interface RoleCreationAttributes extends Optional<RoleAttributes, 'role_id'> {}

class Role extends Model<RoleAttributes, RoleCreationAttributes> implements RoleAttributes {
  public role_id!: number;
  public role_name!: string;
  public role_desc?: string;
}

Role.init({
  role_id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  role_name: {
    type: DataTypes.STRING(50),
    allowNull: false
  },
  role_desc: {
    type: DataTypes.TEXT,
    allowNull: true
  }
}, {
  tableName: 'roles',
  sequelize,  // sequelize 实例
  timestamps: true
});

export default Role;
